import java.util.Scanner;

public class StudentDAO {
    public void displayAllInfo(Object []o){
        if(o==null){
            return ;
        }
        for (int i = 0; i <StudentData.num ; i++) {
            System.out.println(StudentData.getStudent(i).toString());
        }
    }

   public void addStudentInfo(Student stu){
        if(stu==null){
            return;
        }
    StudentAction m=new StudentAction();
    if(m.isExist(stu)!=-1){
        System.out.println("该学号已经存在!!!");
        return;
    }
    int n=StudentData.num+1;
    Student []stuData2=new Student[n];
       for (int i = 0; i <StudentData.num ; i++) {
           stuData2[i]=StudentData.getStudent(i);
       }
       stuData2[n-1]=stu;
       StudentData.stuDataSet(stuData2);
       StudentData.num++;
       System.out.println("成功新增学生信息!");
   }

    public void deleteStudentInfo(String stuNo) {
        StudentAction m = new StudentAction();
        Student []stu1=new Student[StudentData.num-1];
        int j=0;
        for (int i = 0; i < StudentData.num; i++) {
            if(StudentData.getStudent(i).getterStuNo()==stuNo) {
                continue;
            }
            stu1[j]=StudentData.getStudent(i);
            j++;
        }
        StudentData.stuDataSet(stu1);
        System.out.println("成功删除学生信息!");
    }

   public  void updataStudentInfo(String stuNo){
       int i = 0;
       for (; i < StudentData.num; i++) {
           if(StudentData.getStudent(i).getterStuNo().equals(stuNo)) {
               Scanner sc=new Scanner(System.in);
               System.out.println("输入姓名:");
               String b=sc.nextLine();
               System.out.println("输入性别:");
               String c=sc.nextLine();
               System.out.println("输入年龄");
               int d=sc.nextInt();
               StudentData.stuSet(new Student(stuNo,b,c,d),i);
               return;
           }
       }
       if(i==StudentData.num){
           System.out.println("没有该学生!!!");
       }
   }
}


